5.3 - Teleporting the Player


How do we teleport to a specified position?

Teleporting is one of the most simple thing to do. We just need to get the Transform of the LocalPlayer and set it's new position as Vector3.

To do that we need to add two dll references to the mod project:

  • Sons.dll to access the LocalPlayer
  • UnityEngine.dll to use the Vector3 type

In the example below we are teleporting the player to x:4 y:716 z:-459, which correspond to the top of the mountain:


using SonsSdk;
using UnityEngine;
using TheForest.Utils;

namespace TeleportMod;

public class TeleportMod : SonsMod
{
    protected override void OnGameStart()
    {
        LocalPlayer.Transform.position = new Vector3(4, 716, -459);
    }
}